package com.weiwei.diancan.view;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.weiwei.diancan.R;
import com.weiwei.diancan.bean.LoginBean;

/**
 * Created by BMW on 2016/11/6.
 */
public class VersionDialog extends Dialog implements View.OnClickListener {

    private final TextView tv_cancel;
    private final TextView tv_update;
    private final TextView tv_title;
    private final TextView tv_message;
    private Activity context;

    private OnUpdateListener listener;

    private String url;


    public TextView getTv_update() {
        return tv_update;
    }

    public void setMessage(String message){
        if(tv_message!=null) {
            tv_message.setText(message);
        }
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public VersionDialog(Activity context) {
        super(context, R.style.share_dialog);
        this.context = context;
        View v = LayoutInflater.from(context).inflate(R.layout.version_dialog, null);
        tv_cancel = (TextView)v.findViewById(R.id.tv_cancel);
        tv_update = (TextView)v.findViewById(R.id.tv_update);
        tv_title = (TextView)v.findViewById(R.id.tv_title);
        tv_message = (TextView)v.findViewById(R.id.tv_message);
        tv_cancel.setOnClickListener(this);
        tv_update.setOnClickListener(this);
        addContentView(v,
                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT));
    }

    public OnUpdateListener getListener() {
        return listener;
    }

    public void setListener(OnUpdateListener listener) {
        this.listener = listener;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_cancel:
                cancel();
                break;
            case R.id.tv_update:
                if(listener!=null){
                    listener.onClick(v,url);
                    cancel();
                }
                break;
        }
    }

    public interface OnUpdateListener{
        void onClick(View v, String url);
    }
}
